/*
 * @Author: xuman
 * @Date: 2020-04-08 17:30:48
 * @LastEditors: xuman
 * @LastEditTime: 2020-06-23 17:46:32
 */

export const isValidUsername = (str: string) =>
  ['admin', 'editor'].indexOf(str.trim()) >= 0

export const isExternal = (path: string) =>
  /^(\/https?:|\/mailto:|\/tel:)/.test(path)

export const isArray = (arg: any) => {
  if (typeof Array.isArray === 'undefined') {
    return Object.prototype.toString.call(arg) === '[object Array]'
  }
  return Array.isArray(arg)
}

export const isValidURL = (url: string) => {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}
export const isValidMobile = (mobile: string) => {
  const reg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/
  return reg.test(mobile)
}

export const isValidEmail = (email: string) => {
  const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
  return reg.test(email)
}
export const isValidCertNo = (certNo: string) => {
  const reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  return reg.test(certNo)
}

export const isValidCardNo = (cardNo: string) => {
  const reg = /^([1-9]{1})(\d{9,18})$/
  return reg.test(cardNo)
}

// 验证英文、数字、下划线
export const isValidName = (val: string) => {
  const reg = /^[0-9a-zA-Z_]{1,}$/
  return reg.test(val)
}
